package com.lw.vod.controller;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.DeleteVideoRequest;
import com.aliyuncs.vod.model.v20170321.DeleteVideoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.lw.commonutil.result.Result;
import com.lw.commonutil.result.ResultCodeEnum;
import com.lw.commonutil.utils.JwtUtils;
import com.lw.servicebase.exception.GuliException;
import com.lw.vod.client.CourseFeignClient;
import com.lw.vod.client.OrderFeignClient;
import com.lw.vod.service.VodService;
import com.lw.vod.utils.ConstantPropertiesUtil;
import com.lw.vod.utils.InitVodClient;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/vod")
public class VodController {
    @Autowired
    private VodService vodService;
    //上传视频至阿里云
    @PostMapping("/uploadVideo")
    public Result uploadVideo(MultipartFile file){
        //返回上传视频id
        String videoId = vodService.uploadVideo(file);
        return Result.ok(videoId);
    }
    //根据视频id删除视频
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable String id){
        try{
            //初始化对象
            DefaultAcsClient client = InitVodClient.initVodClient( ConstantPropertiesUtil.KEY_ID, ConstantPropertiesUtil.KEY_SECRET );
            //创建删除视频request对象
            DeleteVideoRequest request = new DeleteVideoRequest();
            //向request对象中设置视频id
            request.setVideoIds( id );
            //调用方法实现删除
            client.getAcsResponse( request );
            return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            throw new GuliException( ResultCodeEnum.FAIL );
        }
    }

}
